/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.cip.esymons.tramite.beans;

import java.util.List;
import javax.faces.model.SelectItem;
import org.cip.esymons.tramite.bc.ViaDelegate;
import org.cip.esymons.general.be.Via;

/**
 *
 * @author ADMINISTRADOR
 */
public class viaController {

    private ViaDelegate delegado;
    private Via via;

    public viaController() {

        delegado = new ViaDelegate();
        via = new Via();
    }

    public ViaDelegate getDelegado() {
        return delegado;
    }

    public void setDelegado(ViaDelegate delegado) {
        this.delegado = delegado;
    }

    public Via getVia() {
        return via;
    }

    public void setVia(Via via) {
        this.via = via;
    }

    public Via buscarPorCodigo(Integer codigo){

        return delegado.find(codigo);
    }

    public List<Via> getListaVia(){

        return delegado.findAll();
    }

    public SelectItem[] getselectListaItemVia(){

      try{
        System.out.println("Ingreso 1");
        SelectItem[] selects = null;
        List<Via> listaVia = delegado.findAll();
        selects = new SelectItem[listaVia.size()];
        int cont = 0;
        for(Via vi : listaVia){

            SelectItem item = new SelectItem(vi, vi.getViaNombre());
            selects[cont] = item;
            cont++;
        }
        return selects;
      }catch(Exception e){
            System.out.println("Ingreso Error");
            SelectItem[] selects = new SelectItem[1];
            SelectItem item = new SelectItem(null, "No existen vias");
            selects[0] = item;
            return selects;
      }

    }





}
